<template>
  <div class="activityManagement"
       v-loading.fullscreen.lock="loading">
    <el-tabs v-model="activeName"
             @tab-click="handleClick">
      <el-tab-pane label="发起评价"
                   name="start"></el-tab-pane>
      <el-tab-pane label="查看评价"
                   name="look"></el-tab-pane>
    </el-tabs>
    <!-- 发起评价 -->
    <div class="StartEvaluate"
         v-if="activeName === 'start'">
      <el-row :gutter="20">
        <el-form label-width="90px">
          <el-col :span="6">
            <el-form-item label="被评价人员">
              <el-input v-model="StartrequestParam.search_word"
                        placeholder="请输入被评价人员"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="岗位名称">
              <el-select v-model="StartrequestParam.job_name"
                         placeholder="请选择">
                <el-option v-for="(option,index) in jobNameList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="一级机构">
              <el-select v-model="StartrequestParam.one_organ"
                         @change="changeOne"
                         placeholder="请选择一级机构">
                <el-option v-for="(option,index) in oneOrganList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="二级机构">
              <el-select v-model="StartrequestParam.two_organ"
                         @change="changeTwo"
                         placeholder="请选择二级机构">
                <el-option v-for="(option,index) in startOrgan.twoOrganList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="三级机构">
              <el-select v-model="StartrequestParam.three_organ"
                         @change="changeThree"
                         placeholder="请选择三级机构">
                <el-option v-for="(option,index) in startOrgan.threeOrganList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="四级机构">
              <el-select v-model="StartrequestParam.four_organ"
                         @change="changeFour"
                         placeholder="请选择四级机构">
                <el-option v-for="(option,index) in startOrgan.fourOrganList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="五级机构">
              <el-select v-model="StartrequestParam.five_organ"
                         @change="changeFive"
                         placeholder="请选择五级机构">
                <el-option v-for="(option,index) in startOrgan.fiveOrganList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="六级机构">
              <el-select v-model="StartrequestParam.six_organ"
                         placeholder="请选择六级机构">
                <el-option v-for="(option,index) in startOrgan.sixOrganList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="活动名称">
              <el-input v-model="StartrequestParam.title"
                        placeholder="请输入活动名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="问卷名称">
              <el-select v-model="StartrequestParam.exercise_id"
                         placeholder="请选择问卷名称">
                <el-option v-for="(option,index) in testListArr"
                           :key="index"
                           :value="option.exercise_id"
                           :label="option.exercise_name"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="
                           12"
                  class="flex-end">
            <el-button @click="search('start')"
                       type="primary">查询</el-button>
            <el-button @click="reset('start')">重置</el-button>
          </el-col>
        </el-form>
      </el-row>
      <el-row>

        <el-col :span="24"
                style="margin-bottom:20px">
          <el-button @click="addEvaluate"
                     type="primary">新增被评价人员</el-button>
          <el-button @click="inform"
                     :disabled="checkedIds.length>0?false:true"
                     :type="checkedIds.length>0?'primary':'info'">通知</el-button>
          <el-button @click="jobAddOpera"
                     type="primary">按岗位新增</el-button>
        </el-col>
        <el-col :span="24">
          <el-table :highlight-current-row="true"
                    border
                    ref="activityTable"
                    :row-key="getId"
                    @selection-change="checkPeople"
                    :header-cell-style="{ background: '#f5f5f5' }"
                    :data="startEvaluateList.list">
            <el-table-column type="selection"
                             :reserve-selection="true"
                             width="55">
            </el-table-column>
            <el-table-column type="index"
                             label="序号"
                             sortable
                             align="center"
                             width="80"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="title"
                             label="活动名称"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="exercise_name"
                             label="问卷名称"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="person_name"
                             label="被评价人员"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="评价人数"
                             prop="evaluator_num"
                             align="center">
            </el-table-column>
            <el-table-column label="岗位"
                             show-overflow-tooltip
                             prop="job_name"
                             align="center">
            </el-table-column>
            <el-table-column prop="one_organ"
                             label="一级机构"
                             width="100"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="two_organ"
                             label="二级机构"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="three_organ"
                             label="三级机构"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="four_organ"
                             label="四级机构"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="five_organ"
                             label="五级机构"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="六级机构"
                             prop="six_organ"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="操作"
                             fixed="right"
                             width="200px"
                             align="center">
              <template slot-scope="scope">
                <el-button type="text"
                           @click="lookPeople(scope.row)">评价人员</el-button>
                <el-button @click="deleteStartPeople(scope.row)"
                           type="text">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
        <el-col :span="24"
                style="margin-top:20px!important;">
          <el-pagination @current-change="handleStartPageChange"
                         @size-change="handleStartSizeChange"
                         :current-page="StartrequestParam.page"
                         :page-size="StartrequestParam.page_size"
                         layout="total,sizes,prev, pager, next, jumper"
                         background
                         :total="startEvaluateList.total_count"
                         align="center">
          </el-pagination>
        </el-col>
      </el-row>
    </div>
    <!-- 查看评价 -->
    <div class="StartEvaluate"
         v-if="activeName === 'look'">
      <el-row :gutter="20">
        <el-form label-width="90px">
          <el-col :span="6">
            <el-form-item label="被评价人员">
              <el-input v-model="LookrequestParam.search_word"
                        placeholder="请输入被评价人员"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="岗位名称">
              <el-select v-model="LookrequestParam.job_name"
                         placeholder="请选择">
                <el-option v-for="(option,index) in jobNameList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="一级机构">
              <el-select v-model="LookrequestParam.one_organ"
                         @change="changeOne"
                         placeholder="请选择一级机构">
                <el-option v-for="(option,index) in oneOrganList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="二级机构">
              <el-select v-model="LookrequestParam.two_organ"
                         @change="changeTwo"
                         placeholder="请选择二级机构">
                <el-option v-for="(option,index) in lookOrgan.twoOrganList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="三级机构">
              <el-select v-model="LookrequestParam.three_organ"
                         @change="changeThree"
                         placeholder="请选择三级机构">
                <el-option v-for="(option,index) in lookOrgan.threeOrganList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="四级机构">
              <el-select v-model="LookrequestParam.four_organ"
                         @change="changeFour"
                         placeholder="请选择四级机构">
                <el-option v-for="(option,index) in lookOrgan.fourOrganList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="五级机构">
              <el-select v-model="LookrequestParam.five_organ"
                         @change="changeFive"
                         placeholder="请选择五级机构">
                <el-option v-for="(option,index) in lookOrgan.fiveOrganList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="六级机构">
              <el-select v-model="LookrequestParam.six_organ"
                         placeholder="请选择六级机构">
                <el-option v-for="(option,index) in lookOrgan.sixOrganList"
                           :key="index"
                           :value="option.field_value"
                           :label="option.field_value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="开始时间">
              <el-date-picker v-model="timeVal"
                              type="daterange"
                              @change="chooseTime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              :default-time="['00:00:00','23:59:59']"
                              range-separator="至"
                              start-placeholder="开始日期"
                              end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="活动名称">
              <el-input v-model="LookrequestParam.title"
                        placeholder="请输入活动名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="问卷名称">
              <el-select v-model="LookrequestParam.exercise_id"
                         placeholder="请选择问卷名称">
                <el-option v-for="(option,index) in testListArr"
                           :key="index"
                           :value="option.exercise_id"
                           :label="option.exercise_name"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="评价情况">
              <el-select v-model="LookrequestParam.evaluate_status"
                         placeholder="请选择问卷名称">
                <el-option v-for="(option,index) in evaStatusArr"
                           :key="index"
                           :value="option.value"
                           :label="option.name"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6"
                  :offset="18"
                  class="flex-end look-eva">
            <el-button @click="search('look')"
                       type="primary">查询</el-button>
            <el-button @click="reset('look')">重置</el-button>
            <el-button @click="print('current')"
                       v-auth="'export-file-btn'"
                       type="primary">打印报表</el-button>
            <el-button @click="print('all')"
                       type="primary">导出全部</el-button>
          </el-col>
        </el-form>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-table :highlight-current-row="true"
                    border
                    :header-cell-style="{ background: '#f5f5f5' }"
                    :data="lookEvaluateList.list">
            <!-- <el-table-column type="selection"
                             width="55">
            </el-table-column> -->
            <el-table-column type="index"
                             label="序号"
                             sortable
                             align="center"
                             width="80"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="title"
                             label="活动名称"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="exercise_name"
                             label="问卷名称"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="person_name"
                             label="被评价人员"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="开始日期"
                             show-overflow-tooltip
                             width="120"
                             prop="start_date"
                             align="center">
            </el-table-column>
            <el-table-column label="接收日期"
                             width="120"
                             show-overflow-tooltip
                             prop="end_date"
                             align="center">
            </el-table-column>
            <el-table-column prop="evaluator_num"
                             label="总评价人数"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="evaluated_num"
                             label="已评价人数"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="平均分值"
                             show-overflow-tooltip
                             prop="avg_score"
                             align="center">
            </el-table-column>
            <el-table-column label="评价情况"
                             show-overflow-tooltip
                             prop="evaluate_status"
                             align="center">
              <template slot-scope="scope">
                <p>{{scope.row.evaluate_status === '1' ?'未完成' : '已完成'}}</p>
              </template>
            </el-table-column>
            <el-table-column label="岗位"
                             show-overflow-tooltip
                             prop="job_name"
                             align="center">
            </el-table-column>
            <el-table-column prop="one_organ"
                             label="一级机构"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="two_organ"
                             label="二级机构"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="three_organ"
                             label="三级机构"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="four_organ"
                             label="四级机构"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="five_organ"
                             label="五级机构"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="六级机构"
                             prop="six_organ"
                             align="center"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="操作"
                             fixed="right"
                             width="200px"
                             align="center">
              <template slot-scope="scope">
                <el-button type="text"
                           v-auth="'del-eval-button'"
                           @click="onDelEva(scope.row)">删除</el-button>
                <el-button type="text"
                           @click="resend(scope.row)">重发</el-button>
                <el-button type="text"
                           @click="detailAdd(scope.row)">详情</el-button>
                <!-- <el-button @click="deleteLookPeople(scope.row)"
                           type="text">删除</el-button> -->
              </template>
            </el-table-column>
          </el-table>
        </el-col>
        <el-col :span="24"
                style="margin-top:20px!important;">
          <el-pagination @current-change="handleLookPageChange"
                         @size-change="handleLookSizeChange"
                         :current-page="LookrequestParam.page"
                         :page-size="LookrequestParam.page_size"
                         :page-sizes="[10,20,30,40,50,100,500]"
                         layout="total,sizes,prev, pager, next, jumper"
                         background
                         :total="lookEvaluateList.total_count"
                         align="center">
          </el-pagination>
        </el-col>
      </el-row>
    </div>
    <!-- 新建活动 -->
    <NewAddActivityDialog v-if="newActDialog==true"
                          :testListArr.sync="testListArr"
                          :newActDialog.sync="newActDialog"
                          :callBack="callBack"></NewAddActivityDialog>
    <!-- 按钮岗位新增 -->
    <SelEvaPositeDialog v-if="selEvaPoDialog==true"
                        :testListArr.sync="testListArr"
                        :callBack="callBack"
                        :selEvaPoDialog.sync="selEvaPoDialog"></SelEvaPositeDialog>
    <!-- 模板列表弹框 -->
    <el-dialog title="选择打印模板"
               :visible.sync="dialogVisiblePrintFlag">
      <el-table ref="singleTable"
                :data="printTemplateList"
                highlight-current-row
                @current-change="handleRowChange"
                style="width: 100%">
        <el-table-column property="templete_name"
                         label="模板名称">
        </el-table-column>
      </el-table>
      <div slot="footer"
           class="dialog-footer">
        <el-button @click="dialogVisiblePrintFlag = false">取 消</el-button>
        <el-button type="primary"
                   @click="toPrintPage">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 导出文件html模板 -->
    <div v-show="false"
         id="fileTemplate">
      <table class="table-header">
        <tr>
          <th>序号</th>
          <th>活动名称</th>
          <th>问卷名称</th>
          <th>被评价人员</th>
          <th>开始日期</th>
          <th>接收日期</th>
          <th>总评价人数</th>
          <th>已评价人数</th>
          <th>平均分值</th>
          <th>评价情况</th>
          <th>岗位</th>
          <th>一级机构</th>
          <th>二级机构</th>
          <th>三级机构</th>
          <th>四级机构</th>
          <th>五级机构</th>
          <th>六级机构</th>
        </tr>
        <div v-if="printType=='current'">
          <tr v-for="(item,i) in  lookEvaluateList.list"
              :key="item.assessee_data_id">
            <td>{{i+1}}</td>
            <td>{{item.title}}</td>
            <td>{{item.exercise_name}}</td>
            <td>{{item.person_name}}</td>
            <td>{{item.start_date}}</td>
            <td>{{item.end_date}}</td>
            <td>{{item.evaluator_num}}</td>
            <td>{{item.evaluated_num}}</td>
            <td>{{item.avg_score}}</td>
            <td>{{item.evaluate_status==='1'?'未完成':'已完成'}}</td>
            <td>{{item.job_name}}</td>
            <td>{{item.one_organ}}</td>
            <td>{{item.two_organ}}</td>
            <td>{{item.three_organ}}</td>
            <td>{{item.four_organ}}</td>
            <td>{{item.five_organ}}</td>
            <td>{{item.six_organ}}</td>
          </tr>
        </div>
        <div v-else>
          <tr v-for="(item,i) in  lookEvaluateAllList"
              :key="item.assessee_data_id">
            <td>{{i+1}}</td>
            <td>{{item.title}}</td>
            <td>{{item.exercise_name}}</td>
            <td>{{item.person_name}}</td>
            <td>{{item.start_date}}</td>
            <td>{{item.end_date}}</td>
            <td>{{item.evaluator_num}}</td>
            <td>{{item.evaluated_num}}</td>
            <td>{{item.avg_score}}</td>
            <td>{{item.evaluate_status==='1'?'未完成':'已完成'}}</td>
            <td>{{item.job_name}}</td>
            <td>{{item.one_organ}}</td>
            <td>{{item.two_organ}}</td>
            <td>{{item.three_organ}}</td>
            <td>{{item.four_organ}}</td>
            <td>{{item.five_organ}}</td>
            <td>{{item.six_organ}}</td>
          </tr>
        </div>
      </table>
    </div>

  </div>
</template>

<script>
import { standardCodeApi } from '@/services/StandardCode'
import NewAddActivityDialog from './components/NewAddActivityDialog';
import { backEvaluateApi } from '@/services/ProjectCenter'
import { userPermissionApi } from "@/services/UserPermission";
import SelEvaPositeDialog from './components/SelEvaPositeDialog';//选择被评价人员
import { util } from '@/helper'
export default {
  name: 'activeManagement',
  components: {
    NewAddActivityDialog,//新建活动
    SelEvaPositeDialog,//选择被评价人员
  },
  data () {
    return {
      printType: '',//all:全部;current:当前
      evaStatusArr: [],
      testListArr: [],
      selEvaPoDialog: false,//选择被评价岗位
      newActDialog: false,//新增被评价人员
      timeVal: '', //时间
      checkIds: [],
      activeName: 'start',
      StartrequestParam: {
        title: '',
        exercise_id: '',
        comp_id: '',
        type: '1',
        search_word: '',
        job_name: '',
        one_organ: '',
        two_organ: '',
        three_organ: '',
        four_organ: '',
        five_organ: '',
        six_organ: '',
        is_page: 1,
        page: 1,
        page_size: 10,
      },
      LookrequestParam: {
        evaluate_status: '',
        title: '',
        exercise_id: '',
        comp_id: '',
        type: '2',
        search_word: '',
        job_name: '',
        one_organ: '',
        two_organ: '',
        three_organ: '',
        four_organ: '',
        five_organ: '',
        six_organ: '',
        start_time: '',
        end_time: '',
        is_page: 1,
        page: 1,
        page_size: 10,
      },
      addRequestParam: {
        comp_id: '',
        job_name: '',
        manage_level: '',
        job_level: '',
        one_organ: '',
        two_organ: '',
        three_organ: '',
        four_organ: '',
        five_organ: '',
        six_organ: '',
        is_page: 1,
        page: 1,
        page_size: 10,
      },
      resetParam: {
        evaluate_status: '',
        title: '',
        exercise_id: '',
        search_word: '',
        job_name: '',
        one_organ: '',
        two_organ: '',
        three_organ: '',
        four_organ: '',
        five_organ: '',
        six_organ: '',
        is_page: 1,
        page: 1,
        page_size: 10,
      },
      startcheckList: {
        field: '',
        p_field_value: '',
        p_field: '',
      },
      lookcheckList: {
        field: '',
        p_field_value: '',
        p_field: '',
      },
      addcheckList: {
        field: '',
        p_field_value: '',
        p_field: '',
      },
      jobNameList: [], //岗位名称
      oneOrganList: [], //一级机构
      startOrgan: {
        twoOrganList: [],
        threeOrganList: [],
        fourOrganList: [],
        fiveOrganList: [],
        sixOrganList: [],
      },
      lookOrgan: {
        twoOrganList: [],
        threeOrganList: [],
        fourOrganList: [],
        fiveOrganList: [],
        sixOrganList: [],
      },
      addOrgan: {
        twoOrganList: [],
        threeOrganList: [],
        fourOrganList: [],
        fiveOrganList: [],
        sixOrganList: [],
      },
      startEvaluateList: { //发起评价
        list: [],
        total: 0,
        total_count: 0
      },
      lookEvaluateAllList: [],//导出全部
      lookEvaluateList: {  //查看评价
        list: [],
        total: 0,
        total_count: 0
      },
      addEvaluateList: { //新增被评价
        list: [],
        total: 0,
        total_count: 0
      },
      otherResetParam: {
        two_organ: '',
        three_organ: '',
        four_organ: '',
        five_organ: '',
        six_organ: '',
        is_page: 1,
        page: 1,
        page_size: 10,
      },
      checkedIds: [],
      //选中的list
      getRowKeys (row) {
        //记录每行的key值
        return row.person_id;
      },
      // 打印弹窗是否可见
      dialogVisiblePrintFlag: false,
      printTemplateList: [], // 打印弹窗的模版列表
      choosedTpl: {},
      choosedProject: {},
      loading: false
    }
  },
  async created () {//异步
    let platEvaluateStatus = window.localStorage.getItem('platEvaluateStatus');//评价情况
    if (platEvaluateStatus) {
      this.evaStatusArr = JSON.parse(platEvaluateStatus)
    } else {
      await this.getEvaCode();//评价情况
    }
    await this.getTestList();//问卷名称
    if (this.$route.query.activeType === 'look') {
      this.activeName = this.$route.query.activeType
    }
    let projectLocal = window.localStorage.getItem("choosedProject") || '{}'
    this.choosedProject = JSON.parse(projectLocal)
    await this.getjobNameList()
    await this.getoneOrganList()
    this.StartrequestParam.comp_id = JSON.parse(window.localStorage.userInfo).comp_id// 公司id

    this.search()
  },
  watch: {
    '$store.state.choosedProject': {
      handler (newval) {
        this.choosedProject = newval
      },
      deep: true,
      immediate: true
    }
  },
  mounted () { },
  methods: {
    // 获取评价情况标准码
    getEvaCode () {
      return standardCodeApi.getStandardCodeData({
        data: {
          code_type: 'platEvaluateStatus'
        }
      }).then(res => {
        if (res.code === 0 && res.data.list) {
          this.evaStatusArr = res.data.list
          window.localStorage.setItem('platEvaluateStatus', JSON.stringify(this.evaStatusArr))
        }
      }, err => {
        console.log(err)
      })
    },
    onDel (row) {
      backEvaluateApi.deleteEvaluate({
        params: {
          assessee_data_id: row.assessee_data_id
        }
      }).then((res) => {
        if (res.code === 0) {
          this.$message.success('删除成功!')
          this.search()
        }
      }).catch(err => {
        console.log(err);
      })
    },
    onDelEva (row) {//删除
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        left: true
      }).then(() => {
        this.onDel(row);
      }).catch(() => {
        this.$message.info('已取消删除');
      });
    },
    getId (row) {
      return row.assessee_data_id
    },
    callBack () {
      this.search();//刷新
    },
    //查询
    getTestList () {
      let compId = JSON.parse(window.localStorage.userInfo).comp_id// 公司id
      return backEvaluateApi.getTestList({
        params: {
          comp_id: compId,
          is_page: 0,
        }
      }).then((res) => {
        if (res.code === 0) {
          this.testListArr = res.data.list;
        }
      }).catch(err => {
        console.log(err);
      })
    },
    jobAddOpera () {//按岗位新增
      this.selEvaPoDialog = true;
    },
    print (printTypeVal) {//打印报表
      this.loading = true
      backEvaluateApi.exportAllData({
        params: {
          type: '2',
          is_page: '0',
          ...this.LookrequestParam
        }
      }).then(res => {
        this.loading = false
        let a = document.createElement("a");
        let blob = new Blob([res]);
        a.href = URL.createObjectURL(blob);
        a.download = "查看评价.xlsx";
        a.target = "_blank";
        a.click();
      }, err => {
        this.loading = false
      })

    },
    // 跳转到ureport页面
    toPrintPage () {
      let injections = []
      // let param = JSON.parse(JSON.stringify(this.requestParam))
      let param = {}
      let suffix = ''
      // param.page = 1
      // param.injections = injections
      // param.project_id = this.choosedProject.project_id
      // param.company_id = this.userInfo.comp_id      
      suffix = `project_id=${this.choosedProject.project_id}&search_word=${this.LookrequestParam.search_word}`
      let alink = document.createElement("a");
      alink.target = "_blank";
      let hrefUrl = `http://report.hibuilding.cn/ureport/preview?_u=file:${this.choosedTpl.categ_no}.ureport.xml&${suffix}`;
      alink.href = hrefUrl;
      alink.click();
      alink.remove();
    },
    handleRowChange (row) {
      this.choosedTpl = row
    },
    //获取岗位名称下拉框数据
    getjobNameList () {
      return backEvaluateApi.getSelectList({
        params: {
          comp_id: this.StartrequestParam.comp_id,
          field: 'job_name',
          p_field: '',
          p_field_value: ""
        }
      }).then((res) => {
        this.jobNameList = res.data.list
      }).catch(err => {
        console.log(err);
      })
    },
    handleClick (tab, event) {
      this.checkedIds = []
      this.search()
    },
    //获取一级机构下拉框数据
    getoneOrganList () {
      return backEvaluateApi.getSelectList({
        params: {
          comp_id: this.StartrequestParam.comp_id,
          field: 'one_organ',
          p_field: '',
          p_field_value: ""
        }
      }).then((res) => {
        this.oneOrganList = res.data.list
      }).catch(err => {
        console.log(err);
      })
    },
    //选择一级机构
    changeOne (val) {
      let arr = {
        two_organ: '',
        three_organ: '',
        four_organ: '',
        five_organ: '',
        six_organ: '',
      }
      let newVal = {
        field: 'two_organ',
        p_field: 'one_organ',
        p_field_value: val
      }
      if (this.activeName == 'start') {
        this.startcheckList = newVal
        Object.assign(this.StartrequestParam, arr)
      } else if (this.activeName == 'look') {
        this.lookcheckList = newVal
        Object.assign(this.LookrequestParam, arr)
      }
      this.getelseOrgan()
    },
    //二级
    changeTwo (val) {
      let newVal = {
        field: 'three_organ',
        p_field: 'two_organ',
        p_field_value: val
      }
      if (this.activeName == 'start') {
        this.startcheckList = newVal
      } else if (this.activeName == 'look') {
        this.lookcheckList = newVal
      }
      this.getelseOrgan()
    },
    //三级
    changeThree (val) {
      let newVal = {
        field: 'four_organ',
        p_field: 'three_organ',
        p_field_value: val
      }
      if (this.activeName == 'start') {
        this.startcheckList = newVal
      } else if (this.activeName == 'look') {
        this.lookcheckList = newVal
      }

      this.getelseOrgan()
    },
    //四级
    changeFour (val) {
      let newVal = {
        field: 'five_organ',
        p_field: 'four_organ',
        p_field_value: val
      }
      if (this.activeName == 'start') {
        this.startcheckList = newVal
      } else if (this.activeName == 'look') {
        this.lookcheckList = newVal
      }
      this.getelseOrgan()
    },
    //五级
    changeFive (val) {
      let newVal = {
        field: 'six_organ',
        p_field: 'five_organ',
        p_field_value: val
      }
      if (this.activeName == 'start') {
        this.startcheckList = newVal
      } else if (this.activeName == 'look') {
        this.lookcheckList = newVal
      }
      this.getelseOrgan()
    },
    //获取机构下拉框数据
    getelseOrgan () {
      let param = (this.activeName == 'start') ? this.startcheckList : this.lookcheckList
      //  { comp_id: this.StartrequestParam.comp_id, ...this.checkList }
      backEvaluateApi.getSelectList({
        params: param
      }).then((res) => {
        if (this.activeName === 'start') {
          if (this.startcheckList.field === 'two_organ') {
            this.startOrgan.twoOrganList = res.data.list
          } else if (this.startcheckList.field === 'three_organ') {
            this.startOrgan.threeOrganList = res.data.list
          } else if (this.startcheckList.field === 'four_organ') {
            this.startOrgan.fourOrganList = res.data.list
          } else if (this.startcheckList.field === 'five_organ') {
            this.startOrgan.fiveOrganList = res.data.list
          } else {
            this.startOrgan.sixOrganList = res.data.list
          }
        } else if (this.activeName === 'look') {
          if (this.lookcheckList.field === 'two_organ') {
            this.lookOrgan.twoOrganList = res.data.list
          } else if (this.lookcheckList.field === 'three_organ') {
            this.lookOrgan.threeOrganList = res.data.list
          } else if (this.lookcheckList.field === 'four_organ') {
            this.lookOrgan.fourOrganList = res.data.list
          } else if (this.lookcheckList.field === 'five_organ') {
            this.lookOrgan.fiveOrganList = res.data.list
          } else {
            this.lookOrgan.sixOrganList = res.data.list
          }
        }

      }).catch(err => {
        console.log(err);
      })
    },
    //时间
    chooseTime (val) {
      this.LookrequestParam.start_time = this.timeVal[0]
      this.LookrequestParam.end_time = this.timeVal[1]
    },
    getCurrentData (param) {
      backEvaluateApi.getActivityList({//发起/查看评价
        params: param
      }).then((res) => {
        if (res.code === 0) {
          if (this.activeName === 'start') {//发起
            this.startEvaluateList = res.data
          } else {//查看
            this.lookEvaluateList = res.data
          }
        }
      }).catch(err => {
        console.log(err);
      });
    },
    getLookAllData () {
      this.lookEvaluateAllList = [];//重置
      let LookRequestParams = Object.assign({}, this.LookrequestParam);
      this.$set(LookRequestParams, 'is_page', 0)
      backEvaluateApi.getActivityList({//发起/查看评价
        params: LookRequestParams
      }).then((res) => {
        if (res.code === 0) {
          let list = res.data.list;
          this.lookEvaluateAllList = list;
        }
      }).catch(err => {
        console.log(err);
      });
    },
    //查询
    search () {
      this.LookrequestParam.comp_id = this.StartrequestParam.comp_id
      let param = this.activeName === 'start' ? this.StartrequestParam : this.LookrequestParam
      this.getCurrentData(param);//发起/查看评价
      if (this.activeName === 'look') {//查看

      }
    },
    //重置
    reset () {
      if (this.activeName === 'start') {
        let reset = JSON.parse(JSON.stringify(this.resetParam))
        this.StartrequestParam = Object.assign(this.StartrequestParam, reset)
        this.search()
      } else if (this.activeName === 'look') {
        let reset = JSON.parse(JSON.stringify(this.resetParam))
        this.LookrequestParam = Object.assign(this.LookrequestParam, reset)
        this.timeVal = ''
        this.LookrequestParam.start_time = ''
        this.LookrequestParam.end_time = ''
        this.search()
      }
    },
    //分页-发起评价
    handleStartPageChange (val) {
      this.StartrequestParam.page = val
      this.search()
    },
    handleStartSizeChange (val) {
      this.StartrequestParam.page_size = val
      this.search()
    },
    //分页-查看评价
    handleLookPageChange (val) {
      this.LookrequestParam.page = val
      this.search()
    },
    handleLookSizeChange (val) {
      this.LookrequestParam.page_size = val
      this.search()
    },
    //查询-被评价人员
    addsearch () {
      this.addRequestParam.comp_id = this.StartrequestParam.comp_id
      backEvaluateApi.getchoosePeopleList({
        params: this.addRequestParam
      }).then((res) => {
        if (res.code === 0) {
          this.addEvaluateList = res.data
          this.addEvaluateList.list.forEach((ele) => {   //checkoutTable是选中展示的table数据
            this.checkIds.forEach((item) => {
              if (ele.person_id == item) {
                this.$refs.multipleTable.toggleRowSelection(ele, true);
              }
            })
          })
        }
      }).catch(err => {
        console.log(err);
      })
    },
    addreset () {
      let reset = JSON.parse(JSON.stringify(this.resetParam))
      this.addRequestParam = Object.assign(this.addRequestParam, reset)
      this.addsearch()
      let selArr = {
        twoOrganList: [],
        threeOrganList: [],
        fourOrganList: [],
        fiveOrganList: [],
        sixOrganList: [],
      }
      this.addOrgan = selArr
    },
    //删除-查看评价
    deleteStartPeople (row) {
      this.$confirm('确认删除此次问卷调查记录?', '确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.onDel(row)
      })
    },
    //分页-新增被评价人
    handleAddPageChange (val) {
      this.addRequestParam.page = val
      this.addsearch()
    },
    handleAddSizeChange (val) {
      this.addRrequestParam.page_size = val
      this.addsearch()
    },
    //新增被评价人员
    addEvaluate () {
      this.newActDialog = true;
      this.addreset()
    },
    //选择人通知
    checkPeople (selection, row) {
      this.checkedIds = [];
      if (selection.length > 0) {
        selection.map(item => {
          this.checkedIds.push(item.assessee_data_id)
        })
      }
      // this.checkedIds = row.map(item => item.assessee_data_id)
    },
    //通知
    inform () {
      let ids = this.checkedIds.join(',')
      if (ids === '') {
        this.$alert('尚未选择评价人员, 请选择评价人员', '提示', {
          confirmButtonText: '确定',
          type: 'warning'
        }).then(() => {
        })
      } else {
        backEvaluateApi.informMessage({
          params: {
            assessee_data_ids: ids
          }
        }).then((res) => {
          if (res.code === 0) {
            this.$message.success('通知成功')
            this.checkedIds = []
            this.$refs.activityTable.clearSelection()
            this.search()
          }
        }).catch(err => {
          console.log(err);
        })
      }
    },
    //重发
    resend (row) {
      backEvaluateApi.repeatMessage({
        params: {
          assessee_data_id: row.assessee_data_id
        }
      }).then((res) => {
        if (res.code === 0) {
          this.$message.success('通知成功')
        }
      }).catch(err => {
        console.log(err);
      })

    },
    //评价人员
    lookPeople (row) {
      this.$router.push({ path: '\AddEvaluatePeople', query: { dataId: row.assessee_data_id, personId: row.person_id } })
    },
    //详情
    detailAdd (row) {
      this.$router.push({ path: '\EvaluateDetail', query: { dataId: row.assessee_data_id } })
    },
    //删除-发起评价
    deleteLookPeople (row) {
      this.$confirm('确认删除此次问卷调查记录?', '确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        backEvaluateApi.deleteEvaluate({
          params: {
            assessee_data_id: row.assessee_data_id
          }
        }).then((res) => {
          if (res.code === 0) {
            this.$message.success('删除成功!')
            this.search()
          }
        }).catch(err => {
          console.log(err);
        })
      })
    }
  },
  computed: {},
  watch: {}
}
</script>

<style lang="scss" scoped>
.activityManagement {
  padding: 0 10px;
  .look-eva {
    margin-bottom: 20px;
  }
  .el-tabs {
    padding: 20px;
  }
  .StartEvaluate {
    padding: 20px 10px;
  }
  .el-select {
    width: 100%;
  }
  .el-date-editor.el-input,
  .el-date-editor.el-input__inner {
    width: 100%;
  }
  .el-date-editor /deep/ .el-range-separator {
    width: auto !important;
  }
}
</style>

